home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / technical documentation / develop / develop issue 27 / develop issue 27 code / shapewalker gx / sampleshapewalker.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-03  |  2.6 KB  |  110 lines

  1. /***************
  2.  
  3.   ShapeWalker Test application.
  4.   
  5.   This application converts a piece of text to 
  6.   a path and then uses the shape walker library
  7.   to read the points from the result.  The callback
  8.   routines are used to print out the points in the 
  9.   segments.  
  10.   
  11.   This demonstrates how the library is used for reading 
  12.   gx shapes.
  13.   
  14. **************/
  15.  
  16. #include <stdio.h>
  17. #include "PathWalking.h"
  18.  
  19.  
  20. /***
  21.     The following structure is used
  22.     to maintain a state during walking
  23.     a shape.  It saves the current point
  24.     as well as the first point in a contour
  25. ***/
  26. typedef struct {
  27.  
  28.     gxPoint            currentPoint;                // current pen
  29.     gxPoint            firstPoint;                    // first point in countour.
  30.  
  31. } TestWalkRec;
  32.  
  33. #define fix2float(x) ( (double)x / 65536.0)
  34.  
  35.  
  36. Boolean    TestMoveto(gxPoint *p, TestWalkRec* pWalk);
  37. Boolean    TestMoveto(gxPoint *p, TestWalkRec* pWalk)
  38.     {
  39.         pWalk->currentPoint.x = p->x;
  40.         pWalk->currentPoint.y = p->y;
  41.         
  42.         pWalk->firstPoint.x = p->x;
  43.         pWalk->firstPoint.y = p->y;
  44.         
  45.         printf("Begin new contour: %f, %f\n", fix2float(p->x), fix2float(p->y));
  46.  
  47.         return(false);
  48.     }
  49.  
  50.  
  51.  
  52. Boolean    TestLineto(gxPoint *p, TestWalkRec* pWalk);
  53. Boolean    TestLineto(gxPoint *p, TestWalkRec* pWalk)
  54.     {
  55.         printf("Line from %f, %f to %f, %f\n", fix2float(pWalk->currentPoint.x), 
  56.                                                                                          fix2float(pWalk->currentPoint.y),
  57.                                                                                          fix2float(p->x), fix2float(p->y));
  58.         pWalk->currentPoint.x = p->x;
  59.         pWalk->currentPoint.y = p->y;
  60.  
  61.         return(false);
  62.     }
  63.  
  64.  
  65.  
  66. Boolean    TestCurveTo(gxPoint p[3], TestWalkRec* pWalk);
  67. Boolean    TestCurveTo(gxPoint p[3], TestWalkRec* pWalk)
  68.     {
  69.         printf("Curve from %f, %f through %f, %f, to %f, %f\n",
  70.                         fix2float(p[0].x), fix2float(p[0].y),
  71.                         fix2float(p[1].x), fix2float(p[1].y),
  72.                         fix2float(p[2].x), fix2float(p[2].y));
  73.         
  74.         pWalk->currentPoint.x = p[2].x;
  75.         pWalk->currentPoint.y = p[2].y;
  76.         
  77.         return(false);
  78.     }
  79.  
  80.  
  81.  
  82. Boolean TestClosePath( TestWalkRec* pWalk);
  83. Boolean TestClosePath( TestWalkRec* pWalk)
  84.     {
  85.         printf("Closing the contour\n\n");
  86.             
  87.         pWalk->currentPoint.x = pWalk->firstPoint.x;
  88.         pWalk->currentPoint.y = pWalk->firstPoint.y;
  89.         
  90.         return(false);
  91.     }
  92.  
  93. void main() {
  94.  
  95.     gxShape        theShape;
  96.     gxPoint        location = {ff(100), ff(100)};
  97.     TestWalkRec  walker;
  98.     Boolean        result;
  99.     
  100.     theShape = GXNewText(5, (unsigned char*)"Hello", &location);
  101.     GXSetShapeTextSize(theShape, ff(50));
  102.     GXSetShapeType(theShape, gxPathType);
  103.     GXSetShapeFill(theShape, gxClosedFrameFill);
  104.     
  105.     result = ShapeWalker( theShape, (TpwMovetoProc)TestMoveto, (TpwLinetoProc)TestLineto,
  106.                             (TpwCurvetoProc)TestCurveTo, (TpwClosepathProc)TestClosePath, (void *)&walker); 
  107.  
  108.     GXDisposeShape(theShape);
  109.     
  110. }